package com.tencent.wxcloudrun.service.impl;

import com.tencent.wxcloudrun.dto.Shippingcar;
import com.tencent.wxcloudrun.mapper.ShippingcarMapper;
import com.tencent.wxcloudrun.service.ShippingCarService;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2023/3/15 19:50
 * @description: TODO
 */
@Service
public class ShippingCarServiceImpl implements ShippingCarService {
    @Autowired
    private ShippingcarMapper shippingcarMapper;
    @Override
    public String addShippingCar(String openid, String goodsId, Integer number) {
        String id = getOutTradeNo();
        String adddate = time();
        int i = shippingcarMapper.addShippingCar(number, openid, goodsId,adddate, id);
        return id;
    }

    //生成YYYYMMMDDTMMmm
    public static String time() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss");
        String date = sdf.format(new Date());
        return date ;
    }


    @Override
    public int updateShippingCar(String key, Integer number) {
        return shippingcarMapper.updateShippingCar(key, number);
    }

    @Override
    public int deleteShippingCar(String key) {
        shippingcarMapper.deleteShippingCar(key);
        return 0;
    }

    @Override
    public int deleteShippingCarAll(String openid) {
        shippingcarMapper.deleteShippingCarAll(openid);

        return 0;
    }

    @Override
    public List<Shippingcar> getShippingCar(String openid, String goodsId) {
        return null;
    }

    @Override
    public Shippingcar getShippingCars(String openid, String goodsId) {

        return shippingcarMapper.getShippingCars(openid, goodsId);
    }

    /**
     * 生成订单号22位
     *
     * @return
     */
    public static String getOutTradeNo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String date = sdf.format(new Date());
        String randomstring = RandomStringUtils.randomNumeric(8);
        return date + randomstring;
    }
}
